package com.tedu.controller;

import com.tedu.entity.User;
import com.tedu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //1.获取请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //2.调用业务逻辑
        UserServiceImpl userService = new UserServiceImpl();
        User user = userService.login(new User().setUsername(username).setPassword(password));
        //3.跳转
        if(user == null){
            request.setAttribute("message", "用户名或密码错误！！！");
            //1.转发
            request.getRequestDispatcher("/ems/user/login.jsp").
                    forward(request, response);
        }else{
            //重定向跳转
            response.sendRedirect(request.getContextPath()+"/emp/findAllEmp");
        }
    }
}
